// .........................................................................
// Title: Master_CGS.do
//
// Overall context manager for CGS jobs
// .........................................................................

* ---------------------------------------
* Set up environment
* ---------------------------------------

* main globals
global whoami <WHOAMI>
global code_path <CODE_PATH>
global project_path <PROJECT_PATH>

* paths
global raw "$project_path/raw"
global logs "$project_path/logs"
global tmp "$project_path/temp"
global temp "$project_path/temp"
global graphs "$project_path/graphs"
global output "$project_path/output"
global tables "$project_path/tables"
global holdings "$project_path/holdings"
global morningstar_hd "$output/morningstar_holding_detail"
global insurance_holdings "$project_path/insurance_master"

* create folders
cap mkdir $logs
cap mkdir $tmp
cap mkdir $temp
cap mkdir $graphs
cap mkdir $output
cap mkdir $tables
cap mkdir $holdings
cap mkdir $morningstar_hd
cap mkdir $insurance_holdings
cap mkdir $temp/cgs
cap mkdir $output/cgs

* log file
cap mkdir "$logs/`2'"
cap log close 
log using "$logs/`2'/${whoami}_`2'.log", replace

* run build file
do $code_path/cgs/cgs.do

log close
